<template>
  <div class="pagination_inner">
    <el-pagination
      background
      :page-sizes="pageSizes"
      :page-size="size"
      :small="small"
      :layout="layout"
      :total="total"
      :current-page.sync="page"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
let pageNum = 1;
export default {
  name: 'Pagination',
  props: {
    total: {
      type: Number,
      default: 0,
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 40, 50];
      },
    },
    pageSize: {
      type: Number,
      default: 10,
    },
    small: {
      type: Boolean,
      default: false,
    },
    layout: {
      type: String,
      default: 'total, sizes, prev, pager, next, jumper',
    },
    currentPage: {
      type: Number,
      default: 1,
    },
  },
  data() {
    return {
      size: '',
    };
  },
  computed: {
    page: {
      get() {
        return this.currentPage;
      },
      set(nv) {
        return nv;
      },
    },
  },
  created() {
    this.size = this.pageSize;
  },
  methods: {
    resetPage() {
      this.page = 1;
    },
    handleSizeChange(val) {
      this.size = val;
      this.page = 1;
      this.$emit('search', 1, this.size);
    },
    handleCurrentChange(val) {
      pageNum = val;
      this.$emit('search', pageNum, this.size);
    },
  },
};
</script>

<style lang="scss">
  .el-pagination .btn-prev .el-icon, .el-pagination .btn-next .el-icon{
    font-size: 18px;
  }
  .el-pagination .el-select .el-input .el-input__inner{
    width: 100px;
  }
  .el-pagination__editor.el-input .el-input__inner{
    width: 48px;
  }
  .pagination_inner {
    width: 100%;
    // padding: 20px 0;
    margin-top: 24px;
    text-align: right;
    border-radius: 0 0 4px 4px;
    background: #ffffff;
  }
</style>
